package com.demo.controller;


import com.demo.annotation.GlobalInterceptor;
import com.demo.annotation.VerifyParam;
import com.demo.entity.dto.SessionUserLoginDto;
import com.demo.entity.enums.PermissionCodeEnum;
import com.demo.entity.po.Laboratory;

import com.demo.entity.query.LaboratoryQuery;

import com.demo.entity.vo.ResponseVO;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import com.demo.service.LaboratoryService;

@RestController
@RequestMapping("/laboratory")
public class LaboratoryController extends ABaseController {

	@Resource
	private LaboratoryService laboratoryService;


	/**
	 * 管理员查询实验室信息
	 */
	@RequestMapping("/loadLaboratoryList4Admin")
	@GlobalInterceptor(permissionCode=PermissionCodeEnum.LABORATORY_LIST)
	public ResponseVO loadDataList(LaboratoryQuery query) {
		query.setOrderBy("laboratory_id desc");
		return getSuccessResponseVO(laboratoryService.findListByPage(query));
	}


	/**
	 * 实验室管理教师查询信息
	 * @param query
	 * @return
	 */
	@RequestMapping("/loadLaboratoryList4Teacher")
	@GlobalInterceptor(permissionCode=PermissionCodeEnum.LABORATORY_LIST)
	public ResponseVO loadLaboratoryList4Teacher(HttpSession session,
												 LaboratoryQuery query) {
		SessionUserLoginDto userAdminDto = getUserAdminFromSession(session);
		query.setUserId(userAdminDto.getUserId());
		query.setOrderBy("laboratory_id desc");
		return getSuccessResponseVO(laboratoryService.findListByPage(query));
	}
	/**
	 * 保存实验室信息
	 */
	@RequestMapping("/saveLaboratory")
	@GlobalInterceptor(permissionCode = PermissionCodeEnum.LABORATORY_EDIT)
	public ResponseVO saveLaboratory(Laboratory bean) {
		this.laboratoryService.saveLaboratory(bean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 删除实验室信息
	 * @param id
	 * @return
	 */
	@RequestMapping("/delLaboratory")
	@GlobalInterceptor(permissionCode = PermissionCodeEnum.LABORATORY_DEL)
	public ResponseVO delLaboratory(@VerifyParam(required = true) Integer id) {
		this.laboratoryService.deleteLaboratoryByLaboratoryId(id);
		return getSuccessResponseVO(null);
	}

}